﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorldConqueror.Libraries.Maths.Costants;
using WorldConqueror.Libraries.Maths.MathShapes;

namespace WorldConqueror.Libraries.Maths.Functions.Distance
{
    public class SphericalLawOfCosines : DistanceBetweenCoordinates
    {
        public SphericalLawOfCosines(IMathCoordinate parameter1, IMathCoordinate parameter2)
            : base(parameter1, parameter2)
        {
        }

        public override double CalculateBase(
            double radiansLatitude1, double radiansLongitude1,
            double radiansLatitude2, double radiansLongitude2)
        {
            var distance = Math.Acos(Math.Sin(radiansLatitude1) * Math.Sin(radiansLatitude2) +
                  Math.Cos(radiansLatitude1) * Math.Cos(radiansLatitude2) *
                  Math.Cos(radiansLongitude2 - radiansLongitude1)) * EarthConstants.EarthRadius;

            return distance;
        }
    }
}
